//
//  UIColor+SomeUsefulMethod.m
//  BKJ
//
//  Created by 贝壳家iOS on 15/10/15.
//  Copyright © 2015年 贝壳家iOS. All rights reserved.
//

#import "UIColor+SomeUsefulMethod.h"

@implementation UIColor (SomeUsefulMethod)


+ (UIColor *)defeutBackgroudColor{
    return [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1];
}

+(UIColor *)BKJColor{
    return [UIColor colorWithRed:245/255.0 green:97/255.0 blue:121/255.0 alpha:1];
}

+(UIColor *)Red:(float)red green:(float)green blue:(float)blue alpha:(float)alpha{
    return [UIColor colorWithRed:red/255.f green:green/255.f blue:blue/255.f alpha:alpha];
}

+(UIColor *) hexStringToColor: (NSString *) stringToConvert{
  NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];

  if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
  if ([cString length] != 6) return [UIColor blackColor];
  
  // Separate into r, g, b substrings
  NSRange range;
  range.location = 0;
  range.length = 2;
  NSString *rString = [cString substringWithRange:range];
  range.location = 2;
  NSString *gString = [cString substringWithRange:range];
  range.location = 4;
  NSString *bString = [cString substringWithRange:range];
  // Scan values
  unsigned int r, g, b;
  
  [[NSScanner scannerWithString:rString] scanHexInt:&r];
  [[NSScanner scannerWithString:gString] scanHexInt:&g];
  [[NSScanner scannerWithString:bString] scanHexInt:&b];
  
  return [UIColor Red:(float)r green:(float)g blue:(float)b alpha:1];
}


@end
